var c1Id = $.query.get("categoryLevel1Id");
var c2Id = $.query.get("categoryLevel2Id");
var c3Id = $.query.get("categoryLevel3Id");
var name = $.query.get("name");
var name2 = $.query.get("name2");
var n;

function order(i){
    n=i;
    load(1);
}

function load(pageNow){
    $.getJSON("easybuy/home/productsPage",
        {
            "pageNow":pageNow,
            "categoryLevel1Id":c1Id,
            "categoryLevel2Id":c2Id,
            "categoryLevel3Id":c3Id,
            "name":name,
            "order":n
        },
        function (data) {
            if(data.list.length > 0){
                $(".i_bg .postion").html("<span class=\"fl\">全部 >"+name2+" > </span>\n");
                $(".list_c ul").html("");
                $(".list_c .pages").html("");
                for (var i = 0; i < data.list.length; i++) {
                    $(".list_c ul").append("<li>\n" +
                        "                    \t<div class=\"img\"><a href=\"Product.html?id="+data.list[i].id+"\"><img src=\"images/"+data.list[i].fileName+"\" width=\"210\" height=\"185\" /></a></div>\n" +
                        "                        <div class=\"price\">\n" +
                        "                            <font>￥<span>"+data.list[i].price+"</span></font> &nbsp; 26R\n" +
                        "                        </div>\n" +
                        "                        <div class=\"name\"><a href=\"Product.html?id="+data.list[i].id+"\">"+data.list[i].name+"</a></div>\n" +
                        "                        <div class=\"carbg\">\n" +
                        "                         <input type='hidden' value='"+data.list[i].id+"' class='id'>"+
                        "                        \t<a href=\"javascript:;\" class=\"ss\">收藏</a>\n" +
                        "                            <a href=\"javascript:void(0)\" class=\"j_car\">加入购物车</a>\n" +
                        "                        </div>\n" +
                        "                    </li>");
                }
                $(".list_c .pages").append("<a href=\"javascript:void(0)\">第"+(data.pageNow)+"页/共"+(data.pageCount)+"页</a>");
                $(".list_c .pages").append("<a href=\"javascript:void(0)\" class=\"p_pre\" onclick='load("+(data.pageNow-1)+")'>上一页</a><a href=\"javascript:void(0)\" onclick='load(1)'>1</a>");
                if (data.pageCount>1){
                    $(".list_c .pages").append("<a href=\"javascript:void(0)\" onclick='load(2)'>2</a>");
                }
                if (data.pageCount>2){
                    $(".list_c .pages").append("...<a href=\"javascript:void(0)\" onclick='load("+(data.pageCount)+")'>"+data.pageCount+"</a>");
                }
                $(".list_c .pages").append("<a href=\"javascript:void(0)\" class=\"p_pre\" onclick='load("+(data.pageNow+1)+")'>下一页</a>");

            }else {
                $(".i_bg .postion").html("");
                $(".l_list").html("<h2 style='color: darkred'>没有找到相关商品哦！</h2>");
            }

        });
}



$(function () {
    load(1);
});